package com.ruoyi.web.controller.gd;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.gd.khbjk.domain.vo.ZKhbjkVo;
import com.ruoyi.gd.khbjk.domain.bo.ZKhbjkBo;
import com.ruoyi.gd.khbjk.service.IZKhbjkService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户报价库
 *
 * @author ruoyi
 * @date 2024-07-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/gd/khbjk")
public class ZKhbjkController extends BaseController {

    private final IZKhbjkService iZKhbjkService;

    /**
     * 查询客户报价库列表
     */
    @SaCheckPermission("gd:khbjk:list")
    @GetMapping("/list")
    public TableDataInfo<ZKhbjkVo> list(ZKhbjkBo bo, PageQuery pageQuery) {
        return iZKhbjkService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出客户报价库列表
     */
    @SaCheckPermission("gd:khbjk:export")
    @Log(title = "客户报价库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZKhbjkBo bo, HttpServletResponse response) {
        List<ZKhbjkVo> list = iZKhbjkService.queryList(bo);
        ExcelUtil.exportExcel(list, "客户报价库", ZKhbjkVo.class, response);
    }

    /**
     * 获取客户报价库详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("gd:khbjk:query")
    @GetMapping("/{id}")
    public R<ZKhbjkVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iZKhbjkService.queryById(id));
    }

    /**
     * 导入附件数据
     */
    @Log(title = "导入附件数据", businessType = BusinessType.INSERT)
    @PostMapping("/importData")
    public R<Void> importData(@RequestBody ZKhbjkBo bo) {
        int i = iZKhbjkService.importData(bo);
        return toAjax(i > 0);
    }

    /**
     * 新增客户报价库
     */
    @SaCheckPermission("gd:khbjk:add")
    @Log(title = "客户报价库", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZKhbjkBo bo) {
        return toAjax(iZKhbjkService.insertByBo(bo));
    }

    /**
     * 修改客户报价库
     */
    @SaCheckPermission("gd:khbjk:edit")
    @Log(title = "客户报价库", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZKhbjkBo bo) {
        return toAjax(iZKhbjkService.updateByBo(bo));
    }

    /**
     * 删除客户报价库
     *
     * @param ids 主键串
     */
    @SaCheckPermission("gd:khbjk:remove")
    @Log(title = "客户报价库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iZKhbjkService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
